package com.example.asundae.particletest;

import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Shader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.example.asundae.particletest.boomview.ExplosionField;
import com.example.asundae.particletest.boomview.FallingParticleFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private SimpleDateFormat simpleDateFormat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setTitle("粒子效果Demo          By:super圣代");

        ExplosionField explosionField = new ExplosionField(this , new FallingParticleFactory());
        explosionField.addListener(findViewById(R.id.imageButton));


        textView = (TextView) findViewById(R.id.textView);

        final ExplosionField explosionField1 = new ExplosionField(this , new FallingParticleFactory());
        explosionField1.setOriginalHidde(false);
        explosionField1.addListener(textView);

        textView.getPaint().setShader(new LinearGradient( 0 , 0 , 0 ,
                60 ,
                Color.BLUE ,
                Color.RED ,
                Shader.TileMode.CLAMP)
        );

        simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        new Thread(new Runnable() {
            @Override
            public void run() {
                for(;;)
                {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            textView.setText(simpleDateFormat.format(new Date()));
                            explosionField1.explode(textView);
                        }
                    });
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();
    }

}
